﻿
@{
    ViewData["Title"] = "MeunEdit";
}

@section Scripts
    {
    <script type="text/javascript">
          // 自定义模块
        layui.config({
            base: '/design/lay/modules/',
             version:'v1.2.3'
        }).extend({                         // 模块别名
            authtree: 'authtree'
        });

        var selfLayer = null, page = 1, active = null;
        layui.use(['form', 'layedit', 'authtree'], function () {
            var form = layui.form,authtree = layui.authtree;

            var item = '@ViewData["Id"]';
            console.log(item);

               // 一般来说，权限数据是异步传递过来的
            $.ajax({
                url: '/Role/GetRoleMenu?roleid='+item,
                dataType: 'json',
                success: function (data) {
                    var trees = authtree.listConvert(data.data.list, {
                        primaryKey: 'id'
                        , startPid: '0'
                        , parentKey: 'pid'
                        , nameKey: 'name'
                        , valueKey: 'id'
                        , checkedKey: data.data.checkedId
                    });

                    authtree.render('#LAY-auth-tree-index', trees, {
                        inputname: 'authids[]',
                        layfilter: 'lay-check-auth',
                        autowidth: true,
                    });

                }
            });



              //监听提交
                form.on('submit(submit)', function (data) {
                  data.field.RoleId = item;
                    var checked = authtree.getChecked('#LAY-auth-tree-index');
                  //  console.log('checked', checked);
                    data.field.ListMenuId = checked;
                    axios.get('/Role/AddUpdateRoleMenu', {
                        params: {
                        paramete: data.field
                             }
                    })
                        .then(function (response) {
                            console.log(response.data);
                            if (response.data.Code == 200) {
                                layer.confirm("修改成功，返回列表页？",
                                    function () {
                                        javascript: history.go(-1);
                                    },
                                    function () { location.reload(); });
                            }
                            else {
                                layer.confirm("添加失败!" + response.data.msg)
                            }
                        })
                        .catch(function (error) {
                            layer.confirm("添加失败!")
                            console.log(error)
                        });
                    return false;
                });

             });
    </script>
}

<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">选择权限</label>
        <div class="layui-input-block">
            <div id="LAY-auth-tree-index"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" style="width: 100px" lay-submit="" lay-filter="submit">立即提交</button>
            <a style="width: 100px" class="layui-btn layui-btn-primary backIframe" asp-action="List">返回</a>
        </div>
    </div>
</form>

